package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.constant.BalanceTypeEnum;
import org.jsola.hr.dto.CompanyBalanceRecordAddDTO;
import org.jsola.hr.dto.CompanyBalanceRecordUpdateDTO;
import org.jsola.hr.entity.CompanyBalanceRecordDO;
import org.jsola.hr.query.CompanyBalanceRecordQuery;
import org.jsola.hr.service.ICompanyBalanceRecordService;
import org.jsola.hr.vo.CompanyBalanceRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 用工单位账面余额明细表
 *
 * @author zhr
 */
@Component
public class CompanyBalanceRecordTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICompanyBalanceRecordService companyBalanceRecordService;

    /**
     * 生成add测试数据
     * @return CompanyBalanceRecordAddDTO
     */
    public CompanyBalanceRecordAddDTO getCompanyBalanceRecordAddDTO(){
        CompanyBalanceRecordAddDTO companyBalanceRecordAddDTO = new CompanyBalanceRecordAddDTO();
        companyBalanceRecordAddDTO.setBalanceId(SafeKit.getLong(getRandomValue("bigint",20)));
        companyBalanceRecordAddDTO.setYearly(SafeKit.getInteger(getRandomValue("int",4)));
        companyBalanceRecordAddDTO.setMonthly(SafeKit.getInteger(getRandomValue("int",2)));
        companyBalanceRecordAddDTO.setCompanyId(getRandomValue("text",20000));
        companyBalanceRecordAddDTO.setCompanyName(getRandomValue("varchar",32));
        companyBalanceRecordAddDTO.setSiteName(getRandomValue("varchar",32));
        companyBalanceRecordAddDTO.setChangeType(BalanceTypeEnum.CUSTOMER.getValue());
        companyBalanceRecordAddDTO.setDeleteStatus(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        companyBalanceRecordAddDTO.setSubjectId(getRandomValue("varchar",32));
        companyBalanceRecordAddDTO.setChangeAmount(SafeKit.getBigDecimal(getRandomValue("decimal",20)));
        companyBalanceRecordAddDTO.setBeforeAmount(SafeKit.getBigDecimal(getRandomValue("decimal",20)));
        companyBalanceRecordAddDTO.setAfterAmount(SafeKit.getBigDecimal(getRandomValue("decimal",20)));
        return companyBalanceRecordAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CompanyBalanceRecordUpdateDTO
     */
    public CompanyBalanceRecordUpdateDTO getCompanyBalanceRecordUpdateDTO(CompanyBalanceRecordVO companyBalanceRecordVO){
        return companyBalanceRecordService.selectDOById(companyBalanceRecordVO.getId(), SITE_ID).to(CompanyBalanceRecordUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CompanyBalanceRecordQuery
     */
    public CompanyBalanceRecordQuery getCompanyBalanceRecordQuery() {
        CompanyBalanceRecordQuery companyBalanceRecordQuery = new CompanyBalanceRecordQuery();
        List<CompanyBalanceRecordDO> companyBalanceRecordDOList = companyBalanceRecordService.list(new CompanyBalanceRecordDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(companyBalanceRecordDOList)) {
            CompanyBalanceRecordDO companyBalanceRecordDO = companyBalanceRecordDOList.get(0);
            companyBalanceRecordQuery = companyBalanceRecordDO.to(CompanyBalanceRecordQuery.class);
            if (companyBalanceRecordDO.getGmtCreate() != null) {
                companyBalanceRecordQuery.setGmtCreateStart(DateKit.getBeforeDay(companyBalanceRecordDO.getGmtCreate(),-1));
                companyBalanceRecordQuery.setGmtCreateEnd(DateKit.getBeforeDay(companyBalanceRecordDO.getGmtCreate(),1));
            }
        }
        return companyBalanceRecordQuery;
    }

    /**
     * 保存示例
     * @return CompanyBalanceRecordVO
     */
    public CompanyBalanceRecordVO saveCompanyBalanceRecordExample(){
        CompanyBalanceRecordAddDTO addDTO = this.getCompanyBalanceRecordAddDTO();
        CompanyBalanceRecordVO companyBalanceRecordVO = companyBalanceRecordService.save(addDTO,buildTokenUser());
        return companyBalanceRecordVO;
    }


}

